/* eslint-disable no-restricted-syntax */
import { Module } from 'vuex'
import { resolve } from 'path'
import { reject } from 'lodash'
import Service from '@/api/login'
import { setToken, getToken } from '@/utils/author'

const roles = localStorage.getItem('role') || ''
// create a new Store Modules.
const userModule = {
  namespaced: true,
  state: {
    token: '' || getToken(), // 用户的唯一标志
    userInfo: {} // 用户的基本信息
  },
  mutations: {
    SET_TOKEN(state, data: any) {
      console.log(data)
      state.token = data
    },
    SET_USERINFO(state, data: any) {
      state.userInfo = data
    }
  },
  actions: {
    login(context: any, userInfo: any) {
      context.commit('SET_USERINFO', userInfo.userName)
      if (userInfo.token) {
        setToken(userInfo.token)
      } else {
        const token = 'admin-token'
        setToken(token)
      }
      context.commit('SET_TOKEN', userInfo.token)
    }
  },
  getters: {}
}
export default userModule
